package demo1;

//https://www.nowcoder.com/practice/a8c89dc768c84ec29cbf9ca065e3f6b4?tpId=128&tqId=33769&ru=/exam/oj
//牛客网: 棋子翻转

public class Main {
    public class Solution {
        /**
         * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
         *
         *
         * @param A int整型二维数组
         * @param f int整型二维数组
         * @return int整型二维数组
         */
        public int[][] flipChess (int[][] A, int[][] f) {
            // write code here
            int n = f.length;
            int[] xx = {1,-1,0,0};
            int[] yy = {0,0,1,-1};
            for(int i = 0; i<n; i++) {
                int x = f[i][0]-1;
                int y = f[i][1]-1;
                for(int j = 0; j<4; j++) {
                    int dx = x + xx[j];
                    int dy = y + yy[j];
                    if(dx >= 0 && dx < 4 && dy >= 0 && dy < 4) {
                        if(A[dx][dy] == 1) A[dx][dy] = 0;
                        else A[dx][dy] = 1;
                    }
                }
            }
            return A;
        }
    }
}
